
	 var retentDayArray=[];
     var editIndex = undefined;
     $('#tt').edatagrid({
      	url:"/miguVideoRetentAddConfig/getList",
       onClickRow: function(index){
       	 if($('#smiguVideoId').combobox('getValue')==''){return};
            if(index!=editIndex){
                editIndex = index;
             }
        },
        onLoadSuccess:function(data){
        	$(this).datagrid('enableDnd');
        	retentDayArray=[];

        	if(data.rows.length==0){
        		if($('#smiguVideoId').combobox('getValue')==''){
        			 $('#tt').datagrid({
                        url:'',
                        data:''
        			 }); 
        		}
       	}else{
             	$.each(data.rows,function(index,mod){
           		retentDayArray.push(mod.retentDay)
           	})
       	}
        },
        onBeforeSave:function(index){
       	 var taskNum=$("td[field='taskNum'] input").val();
       	 if(taskNum==''){
       		 return false; 
       	 }
        }
     });
		 
         //查询
         function doSearch(){
        	var miguVideoId=$('#smiguVideoId').combobox('getValue');
        	if(miguVideoId==''||miguVideoId ==undefined){
        		$.messager.alert("提示", "请先选择一个应用");
        		return;
        	}
        		
          	$('#tt').edatagrid({
          		url:"/miguVideoRetentAddConfig/getList?miguVideoId="+miguVideoId});
         }
         
         function remove(){
        		var rows = $("#tt").edatagrid("getSelections");
        	    if (rows&&rows.length>0){
        	    	var arrayId = [];
        	    	for(var i=0;i<rows.length;i++){
        	    		arrayId.push(rows[i].id);
        	    	}
        	    	var ids = arrayId.join(",");
        		    showConfirm(market.content.title, market.content.confirm, function(){
        			  $.post('/miguVideoRetentAddConfig/delete',{ids:ids}, function(data) {
        			  	if (data.return_code == '1') {
        					top.showMsg(market.content.title, data.return_msg, alert);
        					$("#tt").datagrid('reload');
        					$('#tt').datagrid('clearSelections');
        				} else {
        					$.messager.alert(market.content.title, data.return_msg);
        				}
        			  });
        		   });
        	    } else {
        	    	showMsg(market.content.title, market.content.tips, alert);
        	    }
        	}
         
         //添加
         function addRow(){
        	 var miguVideoId=$('#smiguVideoId').combobox('getValue');
         	if(miguVideoId==''||miguVideoId ==undefined){
         		$.messager.alert("提示", "请先选择一个应用");
         		return;
         	}
         	$('#tt').edatagrid('appendRow', {
         		miguVideoId:miguVideoId,    
         		retentMonth:'',
         		execTimes:'1',
                taskNum:'0'
            });
            $('#tt').datagrid('enableDnd');
         }

          //保存
		function saveRow(){
			var miguVideoId=$('#smiguVideoId').combobox('getValue');
        	if(miguVideoId==''||miguVideoId ==undefined){
        		$.messager.alert("提示", "请先选择一个应用");
        		return;
        	}
            var newRow=[];
            var arrayLen=0;
            $('#tt').edatagrid('saveRow')
            var initRow=$("#tt").datagrid('getRows');
 		  	$.each(initRow,function(index,mod){
 		  		var	array={};
 		  		array={miguVideoId:miguVideoId,retentMonth:mod.retentMonth,taskNum:mod.taskNum,execTimes:mod.execTimes};
 		  		newRow.push(array);
 		  		arrayLen=newRow.length;
		  	})
		  
		  	$.ajax({
		  		url:'/miguVideoRetentAddConfig/saveConfig',
		  		type:'post',
		  		dataType:"json",
		  		data:JSON.stringify(newRow),
		  		contentType:'application/json',
		  		success:function(){
		  			jQuery.messager.alert('提示:','成功保存'+arrayLen+'条数据!'); 
		  			doSearch();
		  		}
		  	})
            
        }
        //输入框限制为数字
		$(document).on("keyup afterpaste","td[field='taskNum'] input",function(){
			this.value=this.value.replace(/\D/g,'');
		})
		
		//全选
        function selectAll(){
        	 $('#tt').datagrid('selectAll');
        }
		